package es.deusto.ingenieria.is.search.touringproblem.formulation;


import java.awt.Point;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import es.deusto.ingenieria.is.search.formulation.State;
import es.deusto.ingenieria.is.search.xml.StateXMLReader;



	public class MapReader extends StateXMLReader {

		private Point cityLocation;
		private String cityName;
		private int cities;

		public MapReader(String xmlFile) {
			super(xmlFile);
		}
		
		public State getState() {
			return new EnvironmentMap(
					               this.leftDirt, 
					               this.rightDirt);
		}

		public void startElement(String uri, String localName, String qName,
				Attributes attributes) throws SAXException {
			
			try {		
				if (qName.equals("is:map")) {
					this.cities = Integer.parseInt(attributes.getValue("cities"));
				} else if (qName.equals("is:") && 
						   attributes.getValue("location").equalsIgnoreCase(Location.LEFT.toString())) {
					this.leftDirt = attributes.getValue("dirt").equalsIgnoreCase("yes");
				} else if (qName.equals("aike:room")				
						&& attributes.getValue("location").equalsIgnoreCase(Location.RIGHT.toString())) {
					this.rightDirt = attributes.getValue("dirt").equalsIgnoreCase("yes");
				}
			} catch (Exception ex) {
				System.out.println(this.getClass().getName() + ".startElement(): " + ex);
			}
		}
	}